﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace CommModule.Messages
{
    public class CipheredMessage: Convertible
    {
        private String _cipheredMessageString;

        public String CipheredMessageString
        {
            get { return _cipheredMessageString; }
        }

        public CipheredMessage() { }

        public CipheredMessage(String cipheredMessage)
        {
            _cipheredMessageString = cipheredMessage;
        }

        public void ConvertToCanonic(XmlWriter xmlWriter)
        {
            xmlWriter.WriteStartElement("CipheredMessage");

            if (_cipheredMessageString != null)
            {
                xmlWriter.WriteStartElement("CipheredString");
                xmlWriter.WriteString(_cipheredMessageString);
                xmlWriter.WriteEndElement();
            }

            xmlWriter.WriteEndElement();
        }

        public void ConvertFromCanonic(XmlTextReader xmlTextReader)
        {
            xmlTextReader.ReadStartElement();

            if (xmlTextReader.Name == "CipheredString")
            {
                _cipheredMessageString = xmlTextReader.ReadElementContentAsString();
            }

            xmlTextReader.ReadEndElement();
        }

    }
}
